﻿Public Class informeCCatalogo

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmSalir.Click

        Me.Close()
    End Sub

    Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Dim CatalogoBusiness As New businessCatalogo()
        Dim ListaProductos As New List(Of clsCatalogo)
        Dim Cod_Suc As Int32
        Dim Prod_Id As Int32
        Dim Costo As Decimal
        Dim Marca As String
        Dim Modelo As String
        Dim Nombre As String
        Dim Proveedor As String
        Dim Tipo As String

        Try
            ''Prod_id
            If txtCod.Text.Trim.Length > 0 Then
                Prod_Id = Convert.ToInt32(txtCod.Text.Trim)
            Else
                Prod_Id = 0
            End If

            If txtCosto.Text.Trim.Length > 0 Then
                Costo = Convert.ToDecimal(txtCosto.Text.Trim)
            Else
                Costo = 0
            End If

            Marca = txtMarca.Text.Trim.ToUpper
            Modelo = txtMod.Text.Trim.ToUpper
            Nombre = txtNom.Text.Trim.ToUpper
            Proveedor = txtProv.Text.Trim.ToUpper
            Tipo = txtTipo.Text.Trim.ToUpper

            Select Case cmbSucursal.Text
                Case "SUCURSAL 1"
                    Cod_Suc = 1
                Case "SUCURSAL 2"
                    Cod_Suc = 2
                Case "CASA CENTRAL"
                    Cod_Suc = 3
            End Select

            ListaProductos = CatalogoBusiness.ConsultaCatalogo(Prod_Id, Costo, Marca, Modelo, Nombre, Proveedor, Tipo, Cod_Suc)

            If ListaProductos.Count > 0 Then
                TraeConsulta(ListaProductos)
            Else
                MessageBox.Show("No hay datos para mostrar con los parametros ingresados", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub txtCod_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCod.KeyPress
        validarInt(e)
    End Sub

    Private Sub txtCosto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCosto.KeyPress
        validarDouble(e)
    End Sub

    Private Sub informeCCatalogo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LimpiaFormulario()
    End Sub
    Private Sub LimpiaFormulario()
        txtCod.Text = ""
        txtCosto.Text = ""
        txtMarca.Text = ""
        txtMod.Text = ""
        txtNom.Text = ""
        txtProv.Text = ""
        txtTipo.Text = ""
        cmbSucursal.SelectedIndex = 0
    End Sub

    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        LimpiaFormulario()
    End Sub
    Private Sub TraeConsulta(ByVal ListaProductos As List(Of clsCatalogo))
        consultaCatalogo.ModoAcceso = "INFORME CATALOGO"
        consultaCatalogo.grdCatalogo.DataSource = ListaProductos

        consultaCatalogo.grdCatalogo.Columns(0).DataPropertyName = "Prod_Id"
        consultaCatalogo.grdCatalogo.Columns(1).DataPropertyName = "Descripcion"
        consultaCatalogo.grdCatalogo.Columns(2).DataPropertyName = "Marca"
        consultaCatalogo.grdCatalogo.Columns(3).DataPropertyName = "Modelo"
        consultaCatalogo.grdCatalogo.Columns(4).DataPropertyName = "Tipo"
        consultaCatalogo.grdCatalogo.Columns(5).DataPropertyName = "Costo"
        consultaCatalogo.grdCatalogo.Columns(6).DataPropertyName = "Cantidad"
        consultaCatalogo.grdCatalogo.Columns(7).DataPropertyName = "Proveedor"
        consultaCatalogo.grdCatalogo.Columns(8).DataPropertyName = "Fecha_Ingreso"
        consultaCatalogo.grdCatalogo.Columns(9).DataPropertyName = "Cod_Suc"

        consultaCatalogo.grdCatalogo.Columns(0).HeaderText = "Codigo"
        consultaCatalogo.grdCatalogo.Columns(1).HeaderText = "Descripcion"
        consultaCatalogo.grdCatalogo.Columns(2).HeaderText = "Marca"
        consultaCatalogo.grdCatalogo.Columns(3).HeaderText = "Modelo"
        consultaCatalogo.grdCatalogo.Columns(4).HeaderText = "Tipo"
        consultaCatalogo.grdCatalogo.Columns(5).HeaderText = "Costo"
        consultaCatalogo.grdCatalogo.Columns(6).HeaderText = "Stock"
        consultaCatalogo.grdCatalogo.Columns(7).HeaderText = "Proveedor"
        consultaCatalogo.grdCatalogo.Columns(8).HeaderText = "Fecha Alta"
        consultaCatalogo.grdCatalogo.Columns(9).HeaderText = "Sucursal"

        consultaCatalogo.grdCatalogo.Columns(9).Visible = False

        consultaCatalogo.MdiParent = Me.MdiParent
        Me.Enabled = False
        consultaCatalogo.Show()
    End Sub

End Class